#!/bin/bash

set -e

echo "shell 名称 = $0"

echo "参数一 名称 = $1"

echo "版本号 version = $2"

if [ -z $1 ]
then
  echo "请输入参数 test 或者 prew 或者 prod"
  exit 1
fi

if [ $1 != "test"  ] && [ $1 != "prew" ] && [ $1 != "prod" ]&& [ $1 != "baoji" ]
then
  echo "请输入参数 test 或者 prew 或者 prod"
  exit 1
fi

echo "参数输入正确"

image_name="1"
image_version="v1.0.0"

# if [ -z $2 ]
# then
#   echo "没有输入版本号, 则镜像版本号为默认的": $image_version
# else
# 	image_version=$2
# 	echo "输入了版本号, 则镜像版本号为": $image_version
# fi

#
#

echo "项目开始进行build构建 🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆"
yarn build:${1}
echo "项目build成功   🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉"

#
#

# echo "项目开始构建镜像 🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆"
if [ $1 == "test" ]
then
	# 测试环境
# 宝鸡泵业定制版本
  image_name="192.168.16.11:30002/xmjf-mirgicbox/web-desktop-manage-system-baoji"
  # image_version="v2.0.0"
  image_version="v1.0.21"

elif [ $1 == "prew" ]
then
	# 预发布环境
  image_name="网址/文件夹/镜像名称"
	image_version="v1.0.0"
else
	# 正式环境
  image_name="网址/文件夹/镜像名称"
	image_version="v1.0.0"
fi

echo "镜像名称: " $image_name:$image_version
docker rm -f $image_name
docker rmi -f $image_name:$image_version
docker  build -t $image_name:$image_version --no-cache --platform=linux/amd64 .
echo "镜像构建成功   🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉"

#
#

echo "项目开始推送镜像 🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆🔆"
docker push $image_name:$image_version
echo "项目镜像推送成功 🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉"


